博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring-MVC访问静态资源
阅读量:4677 次
发布时间:2019-06-09

本文共 1737 字,大约阅读时间需要 5 分钟。

Since I spent a lot of time on this issue, I thought I'd share my solution. Since spring 3.0.4, there is a configuration parameter that is called <mvc:resources/> (more about that on the ) which can be used to serve static resources while still using the DispatchServlet on your site's root.

In order to use this, use a directory structure that looks like the following:

src/ springmvc/  web/   MyController.javaWebContent/  resources/   img/    image.jpg  WEB-INF/    jsp/      index.jsp    web.xml    springmvc-servlet.xml
 

The contents of the files should look like:

src/springmvc/web/HelloWorldController.java:

1 package springmvc.web; 2  3 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.RequestMapping; 5  6 @Controller 7 publicclassHelloWorldController{ 8  9  @RequestMapping(value="/")10  publicString index(){11   return"index";12  }13 }

 

 

WebContent/WEB-INF/web.xml:

1 
2
6 7
8
springmvc
9
org.springframework.web.servlet.DispatcherServlet
10
1
11
12 13
14
springmvc
15
/
16
17

 

 

WebContent/WEB-INF/springmvc-servlet.xml:

1 
2
11 12
13
14 15
16
17 18
19
20
22 23 24
25
27
29
30
31 32 33

 

 

WebContent/jsp/index.jsp:

1 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>2 

Page with image

3
4 " />

 

 

Hope this helps :-)

转载于:https://www.cnblogs.com/JavaTechLover/archive/2012/09/01/spring-access-staticResources.html

你可能感兴趣的文章
谷歌浏览器,添加默认搜索引擎的搜索地址
查看>>
数据结构化与保存
查看>>
为什么需要Docker?
查看>>
国内5家云服务厂商 HTTPS 安全性测试横向对比
查看>>
how to control project
查看>>
转 python新手容易犯的6个错误
查看>>
第四节 -- 列表
查看>>
决策树
查看>>
团队作业
查看>>
如何避免在简单业务逻辑上面的细节上面出错
查看>>
大型网站高并发的架构演变图-摘自网络
查看>>
8丶运行及总结
查看>>
Design Pattern --- Strategy
查看>>
mui列表跳转到详情页优化方案
查看>>
一些简单有用的方法合集
查看>>
Neutron 架构 - 每天5分钟玩转 OpenStack(67)
查看>>
详解JS设计模式
查看>>
CPSR寄存器
查看>>
Java基础50题test7—处理字符串
查看>>
保险行业电话外呼型呼叫中心方案
查看>>